﻿package mortal.game.view.copy.groupCopy.view.singleCopyPanel
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.pageSelect.*;
    import mortal.game.view.copy.groupCopy.view.*;
    import mortal.mvc.core.*;

    public class SingleCopyPanel extends GroupCopyBasePanel
    {
        private var _pageSelecter:PageSelecter;
        private var _rewardList:GTileList;
        private var _copyList:GTileList;
        private var _copyName1:GroupCopyName;
        private var _isHidCarrar:Boolean;
        private var _tcopy:TCopy;
        private var _limitNum:BitmapNumberText;
        private var _totalNum:BitmapNumberText;
        private var _btnEnterGroup:GButton;
        private var _bigMap:GImageBitmap;
        private var _copyTitle:GImageBitmap;

        public function SingleCopyPanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.bg(7, 5, 578, 450, this));
            this.pushUIToDisposeVec(UIFactory.bg(7, 458, 578, 92, this));
            this.pushUIToDisposeVec(UIFactory.bg(588, 5, 305, 545, this));
            this._bigMap = UIFactory.gImageBitmap("", 10, 7, this);
            this._copyTitle = UIFactory.gImageBitmap("", 240, 12, this);
            var _loc_1:* = GlobalStyle.textFormatBai.center();
            this._pageSelecter = UIFactory.pageSelecter(674, 410, this, PageSelecter.CompleteMode);
            this._pageSelecter.setbgStlye(ImagesConst.ComboBg, _loc_1);
            this._pageSelecter.currentPage = 1;
            this._pageSelecter.pageTextBoxSize = 50;
            this._pageSelecter.configEventListener(Event.CHANGE, this.onPageChange);
            this._rewardList = UIFactory.tileList(60, 495, 500, 48, this);
            this._rewardList.columnWidth = 48;
            this._rewardList.rowHeight = 48;
            this._rewardList.horizontalGap = 0;
            this._rewardList.verticalGap = 0;
            this._rewardList.setStyle("cellRenderer", GroupCopyRewardCellRender);
            this._copyList = UIFactory.tileList(588, 13, 305, 410, this);
            this._copyList.columnWidth = 305;
            this._copyList.rowHeight = 100;
            this._copyList.horizontalGap = 5;
            this._copyList.verticalGap = -2;
            this._copyList.setStyle("cellRenderer", SingleCopyRender);
            this._copyList.configEventListener(Event.CHANGE, this.handleCellRendererChange);
            this._copyList.selectedIndex = -1;
            this._copyName1 = UICompomentPool.getUICompoment(GroupCopyName);
            this._copyName1.x = 298;
            this._copyName1.y = 464;
            this.addChild(this._copyName1);
            this._limitNum = UIFactory.bitmapNumberText(777, 456, "GroupCopyNum.png", 31, 35, -16, this, 13, BitmapNumberText.Mid);
            this._limitNum.text = "22";
            this._totalNum = UIFactory.bitmapNumberText(829, 456, "GroupCopyNum.png", 31, 35, -16, this, 13, BitmapNumberText.Mid);
            this._totalNum.text = "10";
            this._btnEnterGroup = UIFactory.gButton("" + Language.getString(70884), 704, 512, 84, 27, this, "BrownBtn");
            this._btnEnterGroup.name = "SingleCopy_EnterBtn";
            this._btnEnterGroup.configEventListener(MouseEvent.CLICK, this.clickHandler);
            this.updateCopyList();
            this.updateLimitNum();
            LoaderHelp.addResCallBack(ResFileConst.groupCopy, this.showSkin);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._btnEnterGroup.name = "";
            this._pageSelecter.dispose(param1);
            this._pageSelecter = null;
            this._rewardList.dispose(param1);
            this._rewardList = null;
            this._copyList.dispose(param1);
            this._copyList = null;
            this._copyName1.dispose(param1);
            this._copyName1 = null;
            this._limitNum.dispose(param1);
            this._limitNum = null;
            this._totalNum.dispose(param1);
            this._totalNum = null;
            this._btnEnterGroup.dispose(param1);
            this._btnEnterGroup = null;
            this._bigMap.dispose(param1);
            this._bigMap = null;
            this._copyTitle.dispose(param1);
            this._copyTitle = null;
            return;
        }// end function

        private function showSkin() : void
        {
            if (isDisposed)
            {
                return;
            }
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.GroupCopyBg, 605, 431, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.GroupCopyTxt_1, 605, 458, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.GroupCopyTxt_2, 790, 456, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.GroupCopyTxt_3, 845, 458, this));
            this.addChild(this._limitNum);
            this.addChild(this._totalNum);
            return;
        }// end function

        private function onPageChange(event:Event) : void
        {
            this.updateCopyList();
            this.handleCellRendererChange();
            return;
        }// end function

        private function clickHandler(event:Event) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CopyGroupEnterCopyReq, this._tcopy));
            return;
        }// end function

        private function showMeetCarrarOnly(event:Event) : void
        {
            var _loc_2:* = this._tcopy.rewardShow.split("#");
            this._rewardList.dataProvider = this.getRewardDataProvider(_loc_2);
            return;
        }// end function

        private function getRewardDataProvider(param1:Array) : DataProvider
        {
            var _loc_3:Object = null;
            var _loc_4:ItemData = null;
            var _loc_6:int = 0;
            var _loc_2:* = new DataProvider();
            var _loc_5:* = param1.length;
            while (_loc_6 < _loc_5)
            {
                
                if (param1[_loc_6])
                {
                    _loc_4 = new ItemData(int(param1[_loc_6]));
                    _loc_3 = {itemData:_loc_4};
                    if (_loc_4.itemInfo && ItemsUtil.isFitCarrer(_loc_4))
                    {
                        _loc_3 = {itemData:_loc_4};
                        _loc_2.addItem(_loc_3);
                    }
                }
                _loc_6++;
            }
            return _loc_2;
        }// end function

        private function handleCellRendererChange(event:Event = null) : void
        {
            var _loc_2:* = Cache.instance.role.entityInfo.level;
            if ((this._copyList.selectedItem.tCopy as TCopy).enterMinLevel > _loc_2 && _loc_2 <= (this._copyList.selectedItem.tCopy as TCopy).enterMaxLevel)
            {
                MsgManager.showRollTipsMsg("" + Language.getStringByParam(70885, (this._copyList.selectedItem.tCopy as TCopy).enterMinLevel));
            }
            this._tcopy = this._copyList.selectedItem.tCopy;
            var _loc_3:* = this._tcopy.rewardShow.split("#");
            this._rewardList.dataProvider = this.getRewardDataProvider(_loc_3);
            this._rewardList.x = 17 + (577 - 50 * this._rewardList.dataProvider.length) * 0.5;
            this._bigMap.imgUrl = "singleCopyBigMap_" + this._tcopy.icon + ".jpg";
            this._copyName1.copyUrl = "singleCopyReward_" + this._tcopy.icon + ".png";
            this._copyTitle.imgUrl = "singleCopyName_" + this._tcopy.icon + ".png";
            this._totalNum.text = this._tcopy.dayNum.toString();
            return;
        }// end function

        public function updateCopyList() : void
        {
            this._copyList.dataProvider = this.getCopyDataProvider();
            this._copyList.selectedIndex = 0;
            this.handleCellRendererChange();
            return;
        }// end function

        private function getCopyDataProvider() : DataProvider
        {
            var _loc_3:Object = null;
            var _loc_1:* = new DataProvider();
            var _loc_2:* = CopyConfig.instance.getSingleCopyByLevel(Cache.instance.role.roleInfo.level);
            var _loc_4:* = (this._pageSelecter.currentPage - 1) * 4;
            var _loc_5:* = this._pageSelecter.currentPage * 4 > _loc_2.length ? (_loc_2.length) : (this._pageSelecter.currentPage * 4);
            this._pageSelecter.maxPage = Math.ceil(_loc_2.length / 4);
            var _loc_6:* = _loc_4;
            while (_loc_6 < _loc_5)
            {
                
                _loc_3 = {tCopy:_loc_2[_loc_6]};
                _loc_1.addItem(_loc_3);
                _loc_6++;
            }
            return _loc_1;
        }// end function

        public function updateLimitNum() : void
        {
            this._limitNum.text = Cache.instance.copy.getGroupCopyEnterNum(ECopyType._ECopyTypeSingle).toString();
            return;
        }// end function

    }
}
